home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch18 / rtrace / tri2scn.awk < prev    next >
Text File  |  1993-07-12  |  2KB  |  101 lines

  1. BEGIN {
  2.   OFMT = "%.8g"
  3.   print "#define S1 surface matte red"
  4.   print "#define S2 surface matte green"
  5.   print "#define S3 surface matte yellow"
  6.   print "#define S4 surface matte blue"
  7.   print "#define S5 surface matte magenta"
  8.   print "#define S6 surface matte cyan"
  9.   print "#define S7 surface matte white"
  10.   print "#define S8 surface matte orange"
  11.   print "#define S9 surface matte grey"
  12.   print "#define S10 surface matte ligth_blue"
  13.   print "#define S11 surface metal steel_blue mono 0.9 0.9"
  14.   print "#define S12 surface matte lavender"
  15.   print "#define S13 surface matte brown"
  16.   print "#define S14 surface metal gold mono 0.5 0.5"
  17.   print "#define S15 surface matte misty_rose"
  18.   print "#define S16 surface matte spring_green"
  19.   xmin = 1000000.0
  20.   xmax = -xmin
  21.   ymin = 1000000.0
  22.   ymax = -ymin
  23.   zmin = 1000000.0
  24.   zmax = -zmin
  25. }
  26. NF == 1 {
  27.   ok = 1
  28.   v = 1
  29.   next
  30. }
  31. NF == 7 {
  32.   if (!ok) next
  33.   if (v >= 2 && $1 == lx1 && $2 == ly1 && $3 == lz1) {
  34.     ok = 0
  35.     dgn++
  36.     next
  37.   }
  38.   if (v >= 3 && $1 == lx2 && $2 == ly2 && $3 == lz2) {
  39.     ok = 0
  40.     dgn++
  41.     next
  42.   }
  43.   if ($1 < xmin) xmin = $1
  44.   if ($1 > xmax) xmax = $1
  45.   if ($2 < ymin) ymin = $2
  46.   if ($2 > ymax) ymax = $2
  47.   if ($3 < zmin) zmin = $3
  48.   if ($3 > zmax) zmax = $3
  49.   sx += $1
  50.   sy += $2
  51.   sz += $3
  52.   sn++
  53.   if (v == 1) {
  54.     v = 2
  55.     lx1 = $1
  56.     ly1 = $2
  57.     lz1 = $3
  58.     nx1 = $4
  59.     ny1 = $5
  60.     nz1 = $6
  61.     sf1 = $7
  62.     next
  63.   }
  64.   if ( v == 2) {
  65.     v = 3
  66.     lx2 = $1
  67.     ly2 = $2
  68.     lz2 = $3
  69.     nx2 = $4
  70.     ny2 = $5
  71.     nz2 = $6
  72.     sf2 = $7
  73.     next
  74.   }
  75.   print "triangle general"
  76.   print lx1, ly1, lz1, nx1, ny1, nz1
  77.   print lx2, ly2, lz2, nx2, ny2, nz2
  78.   print $1, $2, $3, $4, $5, $6
  79.   print "S" sf1, "S" sf2, "S" $7
  80.   next
  81. }
  82. {
  83.   # print "error: bad line", NR >"/dev/stderr"
  84.   next
  85. }
  86. END {
  87.   s = xmax - xmin
  88.   if (ymax - ymin > s) s = ymax - ymin
  89.   if (zmax - zmin > s) s = zmax - zmin
  90.   sx /= sn
  91.   sy /= sn
  92.   sz /= sn
  93.   print "eye", sx + 1.5 * s, sy + s * 0.5, sz + s
  94.   print "at", sx, sy, sz
  95.   print "background black"
  96.   print "light point", sx, sy + s, sz
  97.   print "light point", sx + 1.5 * s, sy, sz + s
  98.   # if (dgn) \
  99.   #   print "warning:", dgn, "degenerate triangle(s)" >"/dev/stderr"
  100. }
  101.